Hook Modules
Overview
Hook modules enable custom logic to be executed at specific points in the transaction lifecycle. These hooks can trigger additional actions either before or after a transaction is processed.
- Module Type ID:
MODULE_TYPE_HOOK
- Interface: Implements
IHook
.
Interface
interface IHook is IModule {
function preCheck(
address msgSender,
uint256 msgValue,
bytes calldata msgData
) external returns (bytes memory hookData);
function postCheck(bytes calldata hookData) external;
}
Sample Hook Modules
- GasRefund Hook: Automatically refunds gas costs to the user after a transaction is processed.
- Logging Hook: Logs transaction details to an off-chain service for record-keeping purposes.
Installation and Uninstallation
All modules follow a similar installation and uninstallation process. When a module is installed or uninstalled, the corresponding onInstall
or onUninstall
functions are called with any necessary initialization or cleanup data.
Module Type Verification
Modules implement the isModuleType
function to verify their type (Validator, Executor, Hook, Fallback), as specified by their moduleTypeId
.